﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ELearning.Wpf.UI
{
    /// <summary>
    /// Interaction logic for wndNameEnter.xaml
    /// </summary>
    public partial class wndNameEnter : Window
    {
        public string NewName { get; protected set; }

        public wndNameEnter()
        {
            InitializeComponent();
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                ConfirmEnteredText();
            }
            else if (e.Key == Key.Escape)
            {
                Close();
            }
        }

        private void ConfirmEnteredText()
        {
            lbError.Visibility = Visibility.Hidden;

            if (string.IsNullOrWhiteSpace(tbName.Text))
            {
                lbError.Visibility = Visibility.Visible;
                return;
            }

            NewName = tbName.Text;
            DialogResult = true;
        }

        private void btConfirm_Click(object sender, RoutedEventArgs e)
        {
            ConfirmEnteredText();
        }
    }
}
